<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>拉萨市财政局投资评审管理系统  </title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-1.10.2.min.js"></script>
   <style>
       select{
           height: 70px;
           width: 100%;
       }
   </style>
</head>
<body>
<!--main-header start-->
<div class="main-header">
    <div class="w-1200 clearfix">
        <div class="header-logo fl"><a href=""><img src="images/logo.png"></a> </div>
        <!--header-person start-->
        
        <div id="head_login"></div>
    <script type="text/javascript">
      
      $("#head_login").load("login_common.html");
    </script>
        <!--header-person end-->
        <!--header-nav start-->
        <div class="header-nav fr">
            <ul class="nav">
                <li><a href="/jgindex.html">项目列表</a> </li>
                <li class="on"><a href="/additem.html">新增立项</a> </li>
                <span id="art"></span>
                <script>$("#art").load("artcommon.html")</script>
            </ul>
        </div>
        <!--header-nav end-->
    </div>
</div>
<!--main-header end-->
<!--add-container start-->
<div class="add-container w-1200" id="mainbox">
    <div class="add-content">
        <!--add-item start-->
        <div class="add-item m15" id="ownown">






            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>评审类别：</div>
                    <div class="input-w">
                        <select id="pslb" name="salary">
                           
                        </select>
                    </div>
                </div>
            </div>




        </div>


        <div class="add-item m15">
           
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>评审等级：</div>
                    <div class="input-w">
                       <select name="level" id="level"></select>
                    </div>
                </div>
            </div>
        </div>


        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>行业分类：</div>
                    <div class="input-w">
                        <select id="industry" name="industry">
                            <option value="0">请选择所属行业</option>
                            <option value="1">类别2</option>
                            <option value="2">类别3</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>项目名称：</div>
                    <div class="input-w">
                        <input type="text" id="itemname" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>立项文号：</div>
                    <div class="input-w">
                        <input type="text" id="lxnumber" class="input" placeholder="请输入项目文号">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>项目地址：</div>
                    <div class="input-w">
                        <input type="text" id="address" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>项目标段：</div>
                    <div class="input-w">
                        <input type="text" id="xmbd" class="input">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>项目联系人：</div>
                    <div class="input-w">
                        <input type="text" id="itemcontact" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label w-full"><span class="color-red">*</span>技术评审人意见编号：</div>
                    <div class="name"><input type="text" readonly="readonly" id="yjbh"></div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>委托单位：</div>
                    <div class="input-w">
                        <input type="text" id="wtdw" class="input" readonly="readonly">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>委托单位&nbsp;&nbsp;&nbsp;&nbsp;</br>联系人：</div>
                    <div class="input-w">
                        <input type="text" id="wtdwlxr"  class="input">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>委托单位&nbsp;&nbsp;&nbsp;&nbsp;</br>联系人电话：</div>
                    <div class="input-w">
                        <input type="text" id="wtdwlxrdh" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>编制机构：</div>
                    <div class="input-w">
                        <input type="text" id="bzjg" class="input">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>编制人：</div>
                    <div class="input-w">
                        <input type="text" id="bzr" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>定价依据：</div>
                    <div class="input-w">
                        <input type="text" id="djyj" class="input">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>定额体系：</div>
                    <div class="input-w">
                        <input type="text" id="detx" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item m15">
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>立项金额：</div>
                    <div class="input-w">
                        <input type="text" id="lxje" class="input">
                    </div>
                </div>
            </div>
            <div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>送审投资金额：</div>
                    <div class="input-w">
                        <input type="text" id="sstzje" class="input">
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>立项时间：</div>
                <div class="input-w">
                    <input type="date" id="lxtime"  name="date" class='input edit-input ECalendar'/>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <link rel="stylesheet" href="js/date/date.css">
        <script src="js/date/Ecalendar.jquery.min.js"></script>
        <script type="text/javascript">
            // $(function(){
            //     $("#ECalendar_case1").ECalendar({
            //         type:"date",
            //         skin:"#037d80",
            //         offset:[0,2]
            //     });
            // })
        </script>
        <!--add-item start-->
        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>项目介绍：</div>
                <div class="input-w">
                    <textarea class="txt" rows="6" id="desc"></textarea>
                </div>
            </div>
        </div>
        <input type="hidden" name="" id="owner">
        <!--add-item end-->
        <!--add-item start-->
        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red">*</span>必传：</div>
                <div class="input-w">
                    <div class="add-item-flex">
                        <div class="add-item-up">
        <label><input type="file" multiple="multiple" class="add-item-up-file"   name="file[]" id="file1" /></label>
                            <span><img src="images/add1.png"></span>
                        </div>
                        <div class="add-item-tip">
                            <p>1、预算电子文档（CJZ格式工程文件、IYst格式工程文件或对应软件格式的计价工程文件）</p>
                            <p>2、施工图</p>
                            <p>3、立项文件（写明金额、时间和盖章后的原件扫描件）</p>
                            <p>4、评审申请（盖章后的原件扫描件）</p>
                            <p>5、技术评审意见（盖章后的原件扫描件）</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--add-item end-->
        <!--add-item-files start-->
        <div class="add-item-files" id=filebox>
            
            
        </div>
        <!--add-item-files end-->
        <!--add-item start-->
        <div class="add-item">
            <div class="con w-full">
                <div class="label"><span class="color-red"></span>选传：</div>
                <div class="input-w">
                    <div class="add-item-flex">
                        <div class="add-item-up">
                            <label><input type="file" multiple="multiple" class="add-item-up-file"   name="file[]" id="file2" /></label>
                            <span><img src="images/add2.png"></span>
                        </div>
                        <div class="add-item-tip">
                            <p>1、工程量计算书（EXCEL、软件格式的电子文档）</p>
                            <p>1、工程量计算书（EXCEL、软件格式的电子文档）</p>
                            <p>3、图纸审查报告（盖章后的原件扫描件）</p>
                            <p>4、其他相关资料（提供电子版资料，打包上传）</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="add-item-files" id=filebox2>
            
            
        </div>


        <!--add-item end-->
        <!--add-item-files end-->
        <!--add-bottom start-->
        <div class="add-bottom">
            <button class="login-btn" onclick="subitem()">立即提交</button>
        </div>
        <!--add-bottom end-->
    </div>
</div>
<!--add-container end-->
<!-- <script src="js/jquery.selectlist.js"></script>
<script type="text/javascript">
    $(function(){
        $('select').selectlist({
            zIndex: 10,
            width: 300,
            height: 40
        });
    })
</script> -->
<link rel="stylesheet" href="js/search/autocomplete.css">
<script type="text/javascript" src="js/search/autocomplete.js"></script>
<script type="text/javascript" src="js/ajaxupload.js"></script>
<script src='js/auth.js'></script>
<script type="text/javascript">

    $.get("/api/Index/generatenumber",function(res){
        if(res.result.code==200){
            $("#yjbh").val(res.result.number);
        }
    });
	$(document).ready(function(){
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month) + "-" + (day);
        $('#lxtime').val(today)
        $("#wtdw").val(loginuser.displayname);
        var itemid = getQueryString('id');
        if(itemid){
            $.get("/api/Index/getdetail?id="+itemid,function(res){
                    console.log(res);
                    var item = res.result.item;
                    if(item){
                       $("#industry").val(item.industry);
                       $("#level").val(item.type);
                       $("#itemname").val(item.name);
                       $("#lxnumber").val(item.lxnumber);
                       $("#address").val(item.address);
                       $("#xmbd").val(item.xmbd);
                       $("#itemcontact").val(item.contactor);
                       $("#wtdw").val(item.wtdw);
                        $("#wtdwlxr").val(item.wtdwcontactor);
                        $("#wtdwlxrdh").val(item.wtdwcontactorphone);
                    $('#bzjg').val(item.bzjg);
                    $("#bzr").val(item.bzr);
                    $("#djyj").val(item.djyj);
                    $("#detx").val(item.detx);
                     $("#lxje").val(item.cash);
                    $("#sstzje").val(item.sstzcash);
                    $('#lxtime').val(item.lxtime);
                    $('#desc').val(item.desc);

                    $("#owner").val(item.owner);

                    var restr="";
                    var restr2="";

                    $.each(res.result.files,function(k,v){
                            if(v.ischoose == 0){
                            restr+= `<div class="add-item-files-span">`+v.filename+`：`+v.path+`<span class="close"  onclick="removefile(this)">X</span><input type='hidden' value=`+v.path+` name=`+v.filename+` class='filebox'>
            </div>`;
                }else{
                    restr2+= `<div class="add-item-files-span">`+v.filename+`：`+v.path+`<span class="close"  onclick="removefile(this)">X</span><input type='hidden' value=`+v.path+` name=`+v.filename+` class='filebox2'>
            </div>`;

                }
                        });

                        $("#filebox").append(restr);  
                        $("#filebox2").append(restr2);
                        console.log(item.owner);

                    }
            },'JSON');



        }else{


            var ownerstr= `<div class="w50">
                <div class="con">
                    <div class="label"><span class="color-red">*</span>所属业主：</div>
                    <div class="input-w">
                        <div id="search-form"></div>
                    </div>
                </div>
            </div>`;



            $("#ownown").prepend(ownerstr);


        }




	    //响应文件添加成功事件
	    $("#file1").change(function(){
	        //创建FormData对象
	        var data = new FormData();
	        //为FormData对象添加数据
	        $.each($('#file1')[0].files, function(i, file) {
	            data.append('upload_file'+i, file);
	        });

	       console.log(data);

	        //发送数据
        $.ajax({
	            url:HTTP_HOST+'api/Index/upload',
	            type:'POST',
	            data:data,
	            cache: false,
	            contentType: false, //不可缺参数
	            processData: false,     //不可缺参数
	            success:function(data){
	                console.log(data);

			   var res = ""; 
			$.each(data.result,function(k,v){
				res+= `<div class="add-item-files-span">`+k+`：`+v+`<span class="close"  onclick="removefile(this)">X</span><input type='hidden' value=`+v+` name=`+k+` class='filebox'>
            </div>`;	

			});

			
			   $("#filebox").append(res);

	            },
	            error:function(){
	                alert('上传出错');
	                $(".loading").hide();   //加载失败移除加载图片
	            }
	        });
	    });








        $("#file2").change(function(){
	        //创建FormData对象
	        var data = new FormData();
	        //为FormData对象添加数据
	        $.each($('#file2')[0].files, function(i, file) {
	            data.append('upload_file'+i, file);
	        });

	       console.log(data);

	        //发送数据
        $.ajax({
	            url:HTTP_HOST+'api/Index/upload',
	            type:'POST',
	            data:data,
	            cache: false,
	            contentType: false, //不可缺参数
	            processData: false,     //不可缺参数
	            success:function(data){
	                console.log(data);

			   var res = ""; 
			$.each(data.result,function(k,v){
				res+= `<div class="add-item-files-span">`+k+`：`+v+`<span class="close" onclick="removefile(this)">X</span><input type='hidden' value=`+v+` name=`+k+` class='filebox2'>
            </div>`;	

			});

			   $("#filebox2").append(res);

	            },
	            error:function(){
	                alert('上传出错');
	                $(".loading").hide();   //加载失败移除加载图片
	            }
	        });
	    });



        $.get("/api/Index/getlevels",function(res){

            var levels = res.result.level;
            var opt = "";
            opt+=``;
            $.each(levels,function(k,v){

                opt+=`<option value=`+v.level+`>`+v.level+`</option>`;


            });
            opt+=`</select>`;
            $("#level").html(opt);


            var opt_type = "";
           
            $.each(res.result.type,function(k,v){
                opt_type+=`<option value=`+v.name+`>`+v.name+`</option>`;
            });


            $("#pslb").html(opt_type);


            var industry = "";
           
            $.each(res.result.industry,function(k,v){
                industry+=`<option value=`+v.name+`>`+v.name+`</option>`;
            });


            $("#industry").html(industry);
        },'json');

	});
</script>    


<link rel="stylesheet" href="js/search/autocomplete.css">
<script type="text/javascript" src="js/search/autocomplete.js"></script>
<script type="text/javascript">
    var proposals = null;

    $.ajax({
        url:"api/Index/getowners",
        type:'get',
        async:false,
        success:function(data){
            proposals = data.result;


        }

    });
    console.log(proposals);
    $(document).ready(function(){
        $('#search-form').autocomplete({
            hints: proposals,
            width: 300,
            height: 30,
            onSubmit: function(text){
               
                $('#message').html('Selected: <b>' + text + '</b>');
                var owner = `<input type='hidden' id='owner' value=`+text+`>`;
                $("#search-form").append(owner);
            }
        });
    });


    function removefile(obj){
        console.log("das");

        $(obj).parent().remove();



    }
</script>

<script type="text/javascript">
function phoneFun(phones){
    var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
    if (!myreg.test(phones)) {
        console.log('手机号格式不正确')
      return false;
    } else {
        console.log('手机号格式正确')
      return true;
    }
}
function subitem(){
    var pslb = $("#pslb").val();
var pslb = $("#pslb").val();
    var hyfl = $("#industry").val();
    var level = $("#level").val();
    var name=$("#itemname").val();
    var lxnumber=$("#lxnumber").val();
    var address = $("#address").val();
    var xmbd = $("#xmbd").val();
    var itemcontact = $("#itemcontact").val();
    var wtdw = $("#wtdw").val();
    var wtdwlxr = $("#wtdwlxr").val();
    var wtdwlxrdh = $("#wtdwlxrdh").val();
    var bzjg = $('#bzjg').val();
    var bzr = $("#bzr").val();
    var djyj = $("#djyj").val();
    var detx=$("#detx").val();
    var cash  = $("#lxje").val();
    var sstzje = $("#sstzje").val();
    var yjbh = $("#yjbh").val();
    var lxtime = $('#lxtime').val();
    var owner = $("#owner").val();
    var desc = $("#desc").val();
    var files = [];
    var files2 = [];
    if(owner == undefined || owner == ""){
        console.log(owner);
        alert("你必须选择一个业主,输入关键词，从结果中选取一位业主");
        return false;
    }
    if(phoneFun(wtdwlxrdh) == false){
        alert("手机号格式错误");
        return false;
    }
   $(".filebox").each(function(){
	var filepath = $(this).attr("value");
	var filename = $(this).attr("name");
    files.push({"filename":filename,"filepath":filepath});
   });


   $(".filebox2").each(function(){
	var filepath = $(this).attr("value");
	var filename = $(this).attr("name");
    files2.push({"filename":filename,"filepath":filepath});
   });
   if(hyfl == '' || desc == ''|| level == '' || name == '' || lxnumber == ''|| address == ''|| xmbd == ''|| itemcontact == '' || wtdw == ''|| wtdwlxr == ''|| itemcontact == ''||
   bzjg ==''|| bzr ==''|| djyj == ''| yjbh == ''|| detx == ''| cash == ''|sstzje == ''||owner ==''){

    alert("请检查信息，所有字段必须填写");
    return false;
   }

   if(files.length<5){
       alert("请上传5个必穿文件，你可以一次选择，也可以单个上传");
       return false;
   }


//    if(files2.length<4){
//        alert("请上传4个必穿文件，你可以一次选择，也可以单个上传");
//        return false;
//    }
   var itemid = getQueryString('id');
   var isupdate =false;

   if(itemid){
       isupdate = true;
   }


    $.post(HTTP_HOST+"api/Index/additem",{"owner":owner,
"type":level,"industry":hyfl,"name":name,"lxnumber":lxnumber,
"address":address,"xmbd":xmbd,"contactor":itemcontact,"wtdw":wtdw,
"wtdwcontactor":wtdwlxr,"wtdwcontactorphone":wtdwlxrdh,"bzjg":bzjg,"bzr":bzr,"djyj":djyj,
"detx":detx,"cash":cash,"sstzcash":sstzje,"yjbh":yjbh,"lxtime":lxtime,"approve_type":pslb,"files":files,"file2":files2,'isupdate':isupdate,"id":itemid,"desc":desc},function(res){

	if(res.code == 200){

			alert("添加项目成功");
            window.location.href = "/jgindex.html";

	}else{
        alert("发生错误");
        return false;
    }
    console.log(res);


},'JSON');
    
}

</script>
</body>
</html>
